package com.lwx.sys.utils;


import org.apache.commons.lang3.StringUtils;
import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

/**
 * 获取配置工具类
 * @author gt
 * @date 2020-8-19 17:32
 */
@Component
public class EnvUtil implements EnvironmentAware {
    private static Environment env;

    @Override
    public void setEnvironment(Environment environment) {
        env = environment;
    }

    public static String getString(String key) {
        return env.getProperty(key);
    }

    public static int getInt(String key) {
        String property = getString(key);
        if (StringUtils.isNotBlank(property) && StringUtils.isNumeric(property)) {
            return Integer.parseInt(property);
        }
        return 0;
    }
}
